const path = require('path');
const webpack = require('webpack');
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
const resolve = dir => {
    return path.join(__dirname, dir)
}

 module.exports = {
    devServer: {
        // 设置主机地址
        host: 'localhost',
        // 设置默认端口
        port: 8081,
        open: false,//项目启动时是否自动打开浏览器，我这里设置为false,不打开，true表示打开
        proxy: {
            '/appmanage': {//代理api
                // target: "http://192.168.5.233:8089",//测试api地址
                // target: "http://192.168.7.211:20301",//baofei开发api地址
                // target: "http://192.168.5.244:20301",//开发服务器
                // target: "http://192.168.7.218:20301",//龙地址
                // target: "http://192.168.7.58:20301",//龙地址
                // target: "http://192.168.7.51:20301",//开发api地址
                // target: "http://192.168.193.182:6070",//baofei
                // target: "http://192.168.5.248:8086",//
                changeOrigin: true,//是否跨域
                ws: false, // proxy websockets
                // pathRewrite: {//重写路径
                //     "^/activity": '/activity'
                // }
            }
        }
    },
    configureWebpack: {
        // 把原本需要写在webpack.config.js中的配置代码 写在这里 会自动合并
        externals: {
        },
        plugins: [
            new CompressionWebpackPlugin({
                filename: '[path].gz[query]',
                algorithm: 'gzip',
                test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
                threshold: 10240,
                minRatio: 0.8
            }),
            new webpack.ProvidePlugin({
                jQuery: 'jquery',
                $: 'jquery'
            })
        ],
        optimization:{
            splitChunks: {
                chunks: 'all'
              }
        },
    },
    lintOnSave: true,
    css: {
        loaderOptions: {
            postcss: {
                plugins: [
                    require('postcss-px2rem')({remUnit: 192}), // 换算的基数
                ]
            }
        }
    },
    //样式及 html 模板中引用路径的简写时，前面需要加上 ～ 符
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src'))
            .set('_img', resolve('img'))
            .set('_assets', resolve('src/assets'))
            .set('_components', resolve('src/components'))
            .set('_config', resolve('src/config'))
            config.output.filename('[name].[hash].js').end();
    },
     publicPath: './',
     outputDir: undefined,
     assetsDir: './',
     runtimeCompiler: undefined,
     productionSourceMap: false,
     parallel: undefined
 }
